package com.csthink.auditlog.config.builder;

import com.csthink.auditlog.domain.AuditLogOperator;
import com.csthink.auditlog.util.AuditLogAuthUtil;
import com.csthink.common.infrastructure.enums.Source;
import org.apache.commons.lang3.StringUtils;

/**
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-12
 */
public class AuditLogBuilder extends BaseAuditLogBuilder {

    private Source source;

    private AuditLogBuilder(Source source) {
        this.source = source;
    }

    public static AuditLogBuilder create(Source source) {
        return new AuditLogBuilder(source);
    }

    @Override
    protected void handleAccountInfo() {
        // If set by other way, use that
        if (StringUtils.isNotBlank(this.auditLog.getAccountId())) {
            return;
        }
//        this.auditLog.setAccountId(AuthenticationHelper.getAccountId());

    }

    @Override
    protected void handleOperatorInfo() {
        AuditLogOperator operator = AuditLogAuthUtil.getOperator();
        this.auditLog.setOperatorId(operator.getId());
        this.auditLog.setOperatorInfo(operator.getEmail());
    }

    @Override
    protected void handleSource() {
        this.auditLog.setSource(source.name());
    }

}